﻿using System.Collections.Generic;
using SimpleServiceBus.Endpoint;
using SimpleServiceBus.Endpoint.Metadata;

namespace SimpleServiceBus.Bus.Pipeline
{
    public class MessageContext : IMessageContext
    {
        public MessageContext(MessageEnvelope messageEnvelope,IMessagePipeline pipeline)
        {
            MessageEnvelope = messageEnvelope;
            MessagePipeline = pipeline;

            MessageState = new Dictionary<string, object>();
        }

        public IMessagingEndpoint Endpoint
        {
            get { return MessagePipeline.Endpoint;}
        }

        public IEndpointDescription EndpointMetadata
        {
            get { return Endpoint.Metadata; }
        }

        public IMessagePipeline MessagePipeline
        {
            get; private set;
        }

        public MessageEnvelope MessageEnvelope
        {
            get; private set;
        }

        public bool AbortMessageProcessing
        {
            get; set;
        }

        public IDictionary<string, object> MessageState
        {
            get; private set;
        }

        public T GetLocalService<T>()
        {
            return Endpoint.LocalServices.GetService<T>();
        }
    }
}